package com.hybrid.utils;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import android.annotation.TargetApi;
import android.net.Uri;
import android.text.TextUtils;
import android.util.Log;

public class UriParams {
    private static final String TAG = "BundleParam";
    private final Uri mUri;

    private UriParams(String uri) {
        //this.mUri = (Uri)bundle.getParcelable("intent_data");
        this.mUri = Uri.parse(uri);
    }

    private UriParams(Uri uri) {
        //this.mUri = (Uri)bundle.getParcelable("intent_data");
        this.mUri = uri;
    }

    public static UriParams from(String bundle) {
        return new UriParams(bundle);
    }

    public static UriParams from(Uri bundle) {
        return new UriParams(bundle);
    }

    public int getInt(String key, int defaultValue) {
        try {
            String value = this.mUri.getQueryParameter(key);
            if (TextUtils.isEmpty(value)) {
                return defaultValue;
            }
            return Integer.parseInt(value);
        } catch (Exception var4) {
            Log.d("BundleParam", "IntentParam.getInt parse int from string failed for " + key);
            return defaultValue;
        }
    }

    public long getLong(String key, long defaultValue) {
        try {
            String value = this.mUri.getQueryParameter(key);
            if (TextUtils.isEmpty(value)) {
                return defaultValue;
            }
            return Long.parseLong(value);
        } catch (Exception var5) {
            Log.d("BundleParam", "IntentParam.getLong parse long from string failed for " + key);
            return defaultValue;
        }
    }

    public float getFloat(String key, float defaultValue) {
        try {
            String value = this.mUri.getQueryParameter(key);
            if (TextUtils.isEmpty(value)) {
                return defaultValue;
            }

            return Float.parseFloat(value);
        } catch (Exception var4) {
            Log.d("BundleParam", "IntentParam.getFloat parse float from string failed for " + key);
            return defaultValue;
        }
    }

    public double getDouble(String key, double defaultValue) {
        try {
            String value = this.mUri.getQueryParameter(key);
            if (TextUtils.isEmpty(value)) {
                return defaultValue;
            }
            return Double.parseDouble(value);
        } catch (Exception var5) {
            Log.d("BundleParam", "IntentParam.getDouble parse double from string failed for " + key);
            return defaultValue;
        }
    }

    public boolean getBoolean(String key, boolean defaultValue) {
        try {
            String value = this.mUri.getQueryParameter(key);
            if (TextUtils.isEmpty(value)) {
                return defaultValue;
            }
            return Boolean.parseBoolean(value);
        } catch (Exception var4) {
            Log.d("BundleParam", "IntentParam.getBoolean parse boolean from string failed for " + key);
            return defaultValue;
        }
    }

    public String getString(String key, String defaultValue) {
        try {
            String e = this.mUri.getQueryParameter(key);
            return e == null ? defaultValue : e;
        } catch (Exception var4) {
            return defaultValue;
        }
    }

    @TargetApi(11)
    public Map<String, String> getParameters() {
        try {
            Set e = this.mUri.getQueryParameterNames();
            HashMap params = new HashMap();
            Iterator var3 = e.iterator();

            while (var3.hasNext()) {
                String key = (String)var3.next();
                params.put(key, this.getString(key, ""));
            }

            return params;
        } catch (Exception var5) {
            return new HashMap();
        }
    }
}

